# -*- coding: binary -*-

module Msf::Exploit::Remote::HTTP::Atlassian::Confluence::Version
  def get_confluence_version
    res = send_request_cgi(
      'method' => 'GET',
      'uri' => normalize_uri(target_uri.path, 'login.action')
    )
    return nil unless res&.code == 200

    poweredby = res.get_xml_document.xpath('//ul[@id="poweredby"]/li[@class="print-only"]/text()').first&.text
    return nil unless poweredby =~ /Confluence (\d+(\.\d+)*)/

    Rex::Version.new(Regexp.last_match(1))
  end
end